package com.qnbc.mystery.controller;
import javax.servlet.http.HttpServletResponse;

import com.qnbc.mystery.core.annotation.Log;
import com.qnbc.mystery.core.controller.BaseController;
import com.qnbc.mystery.core.domain.AjaxResult;
import com.qnbc.mystery.core.enums.BusinessType;
import com.qnbc.mystery.core.page.TableDataInfo;
import com.qnbc.mystery.core.utils.poi.ExcelUtil;
import com.qnbc.mystery.pojo.domain.OrderDetail;
import com.qnbc.mystery.service.IOrderDetailService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 子订单
 *
 * @author guzj
 * @date 2024-01-24
 */
@Api("子订单")
@RestController
@RequestMapping("/detail")
public class OrderDetailController extends BaseController {
    @Autowired
    private IOrderDetailService orderDetailService;

    /**
     * 查询子订单列表
     */
    @GetMapping("/list")
    public TableDataInfo list(OrderDetail orderDetail) {
        startPage();
        List<OrderDetail> list = orderDetailService.selectOrderDetailList(orderDetail);
        return getDataTable(list);
    }

    /**
     * 导出子订单列表
     */
    @Log(title = "子订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderDetail orderDetail) {
        List<OrderDetail> list = orderDetailService.selectOrderDetailList(orderDetail);
        ExcelUtil<OrderDetail> util = new ExcelUtil<OrderDetail>(OrderDetail.class);
        util.exportExcel(response, list, "子订单数据");
    }

    /**
     * 获取子订单详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(orderDetailService.selectOrderDetailById(id));
    }

    /**
     * 新增子订单
     */
    @Log(title = "子订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderDetail orderDetail) {
        return toAjax(orderDetailService.insertOrderDetail(orderDetail));
    }

    /**
     * 修改子订单
     */
    @Log(title = "子订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderDetail orderDetail) {
        return toAjax(orderDetailService.updateOrderDetail(orderDetail));
    }

    /**
     * 删除子订单
     */
    @Log(title = "子订单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(orderDetailService.deleteOrderDetailByIds(ids));
    }
}
